package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	ops := map[byte]byte{
		')': '(',
		']': '[',
		'}': '{',
	}

	sc := bufio.NewScanner(os.Stdin)

	var line string
	var stack []byte
	var flag bool

	for sc.Scan() {
		line = sc.Text()

		stack = []byte{}
		flag = true

		for _, c := range line {
			if _, ok := ops[byte(c)]; !ok {
				stack = append(stack, byte(c))
			} else {
				if len(stack) > 0 && stack[len(stack)-1] == ops[byte(c)] {
					stack = stack[:len(stack)-1]
				} else {
					flag = false
					break
				}
			}
		}

		fmt.Println(flag && len(stack) == 0)
	}
}
